package com.wonderful.wedding.api;

import com.wonderful.wedding.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/group")
@SuppressWarnings("unchecked")
public class GroupController {
    @Autowired
    private GroupService groupService;

    @PostMapping()
    public ResponseEntity createGroup(@RequestParam(value = "bridegroomName") String bridegroomName,
                                      @RequestParam(value = "brideName") String brideName) {
        int result = groupService.create(bridegroomName + brideName);
        if (result == 1) {
            return new ResponseEntity("success to create group!", HttpStatus.OK);
        } else {
            if (result == 0) {
                return new ResponseEntity("group existed!", HttpStatus.OK);
            }

            return new ResponseEntity(HttpStatus.BAD_REQUEST);
        }
    }
}
